package com.atguigu.gmall.gateway.config;
/**
 * Project Name: gmall-learn.
 * Package Name: com.atguigu.gmall.gateway.config.
 * File Name: GmallCorsConfig
 * Copyright (c) 2020, 南京天芯云数据服务有限公司.
 */

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 *
 * Class Name: GmallCorsConfig
 * FQDN：com.atguigu.gmall.gateway.config.GmallCorsConfig
 * Author: 阿辉
 * Date: 2020/4/9 14:30
 * Description: 跨域请求处理的东西
 *
 */
@Configuration
public class GmallCorsConfig {

    @Bean
    public CorsWebFilter corsWebFilter(){
        //cors跨域配置对象
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.setAllowCredentials( true );
        corsConfiguration.addAllowedOrigin( "http://localhost:1000");
        corsConfiguration.addAllowedMethod( "*" );
        corsConfiguration.addAllowedHeader( "*" );

        //配置源对象
        UrlBasedCorsConfigurationSource configurationSource = new UrlBasedCorsConfigurationSource(  );
        configurationSource.registerCorsConfiguration( "/**",corsConfiguration);

        //cors过滤对象
        return new CorsWebFilter( configurationSource );
    }
}
